#include <stdio.h>
#include <string.h>

int outline(int in)
{
	int today = 20140906;
	int deadline = 18140906;

	if(in > today || in < deadline)
		return 1;
	else
		return 0;
}

int main(int argc, char **argv)
{
	int i, date, count, temp;

	int i_data[3], max_date = 20140906, min_date = 18140906;

	char old_name[10]={0}, yng_name[10]={0}, i_str[10];
	
	scanf("%d", &count);
	
	for(i=0, temp=count; i < temp; i++)
	{
		scanf("%s%d/%d/%d", i_str, i_data, i_data+1, i_data+2);

		date = i_data[0] * 10000 + i_data[1] * 100 + i_data[2];
		if(date > 20140906 || date < 18140906)
		{
			count--;
			continue;
		}
		else
		{
			if(date < max_date)
			{
				max_date = date;
				strcpy(old_name, i_str);
			}
			if(date > min_date)
			{
				min_date = date;
				strcpy(yng_name, i_str);
			}
		}
	}

	if(strlen(old_name) ==0 && strlen(yng_name) ==0)
		printf("%d\n", count);
	else
		printf("%d %s %s\n", count, old_name, yng_name);
	return 0;
}